package org.itboys.core.controller.front.coupon;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.itboys.core.service.mysql.front.SundayFrontCouponService;
import org.itboys.core.util.AccountIdHoldUtils;
import org.itboys.core.util.MybatisParamUtil;
import org.itboys.core.util.ResponseMessage;
import org.itboys.framework.spring.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: jiaqilei
 * @Date: 11:39 2018/12/13
 * @Discription: 移动端优惠券
 */
@Controller
@RequestMapping("/sunday/mobile/coupon")
@Api(value = "coupon", description = "优惠券")
public class SundayFrontCouponController extends BaseController {

    @Autowired
    private SundayFrontCouponService couponService;

    @RequestMapping(value = "/select", method = RequestMethod.POST)
    @ApiOperation("【租赁端】用户优惠券列表")
    public void select(HttpServletRequest request, HttpServletResponse response
            , @ApiParam(value = "分页参数。每页数量。默认20") @RequestParam(value = "pageSize", required = false) String pageSize
            , @ApiParam(value = "分页参数。第几页。默认1") @RequestParam(value = "pageNumber", required = false) String pageNumber
            , @ApiParam(value = "排序参数。字段名称。默认为空。") @RequestParam(value = "sort", required = false) String sort
            , @ApiParam(value = "排序参数。默认为空。ASC正序/DESC倒序") @RequestParam(value = "order", required = false) String order
    ) {
        Long memberId = AccountIdHoldUtils.getMemberId();
        MybatisParamUtil paramUtil = new MybatisParamUtil(request);
        ResponseMessage.success(couponService.select(paramUtil, memberId));
    }

    @RequestMapping(value = "save", method = RequestMethod.POST)
    @ApiOperation("【租赁端】用户领取优惠券")
    public void save(HttpServletRequest request, HttpServletResponse response
            , @ApiParam(value = "优惠券id") @RequestParam(value = "couponId", required = false) Long couponId
    ) {
        Long memberId = AccountIdHoldUtils.getMemberId();
        couponService.receive(memberId, couponId);
        ResponseMessage.success();
    }
}
